﻿using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using prismFramework_Modules.Events;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace prismFramework.ViewModels
{
    [AddINotifyPropertyChangedInterface]
    public  class MainWindowViewModel
    {
        private readonly IRegionManager _regionManager;
         private readonly IEventAggregator _eventAggregator;
        public MainWindowViewModel(IRegionManager regionManager,IEventAggregator eventAggregator)
        {
            MyCommand = new DelegateCommand(ExecuteSaveCommand);
            MyProperty = "hello";

            _regionManager = regionManager;
            _eventAggregator = eventAggregator;
            // 导航到指定视图
            _regionManager.RequestNavigate("ContentRegion", "ViewA");


            _eventAggregator.GetEvent<MsgEvent>().Subscribe((s) => { MessageBox.Show("收到消息"+s); });


        }
        public string MyProperty { get; set; } 
        public DelegateCommand MyCommand { get; private set; }
        private void ExecuteSaveCommand()
        {
            // 执行保存操作的逻辑
            MyProperty = "123";
            MessageBox.Show(MyProperty);

        }
        private DelegateCommand<string> _navigationCmd;
        public DelegateCommand<string>   NavigationCmd =>
            _navigationCmd ?? (_navigationCmd = new DelegateCommand<string>((s) =>
            {
                _regionManager.RequestNavigate("ContentRegion", s);
            }));

       
        

    }
}
